function test()
{
	alert('test is success')
}

//--------------------------------check--------------------------------------

//remove space, include head and last
function trim(str)
{
	return str.replace(/(^\s*)|(\s*$)/g, "");
}

function checkLetterNum(vl)
{
	var filter=/^[A-Za-z0-9]+$/;
	if( filter.test(vl) ) return true;
	else  return false;
}

function checkNum(vl)
{
	var filter=/^[0-9]\d*$/;
	if( filter.test(vl) ) return true;
	else  return false;
}

function checkNumWithDot(vl)
{
	var filter=/^[0-9]\d*(\.\d{1,2})?$/;  //  /^[\+-]?[0-9]?\d*(\.\d{1,2})?$/
	if(filter.test(vl))  return true;
	else  return false;
}

function checkPhone(vl)
{
	var filter=/^\s*[.0-9_-]{0,15}\s*$/;
	if(filter.test(vl))  return true;
	else  return false;
}

function checkEmail(vl)
{
	var filter=/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
	if(filter.test(vl))  return true;
	else  return false;
}

//compare date
function checkDate(DateOne,DateTwo)
{
	var OneMonth = DateOne.substring(5,DateOne.lastIndexOf ("-"));
	var OneDay = DateOne.substring(DateOne.length,DateOne.lastIndexOf ("-")+1);
	var OneYear = DateOne.substring(0,DateOne.indexOf ("-"));

	var TwoMonth = DateTwo.substring(5,DateTwo.lastIndexOf ("-"));
	var TwoDay = DateTwo.substring(DateTwo.length,DateTwo.lastIndexOf ("-")+1);
	var TwoYear = DateTwo.substring(0,DateTwo.indexOf ("-"));

	if (Date.parse(OneMonth+"/"+OneDay+"/"+OneYear) > Date.parse(TwoMonth+"/"+TwoDay+"/"+TwoYear))
	{
	  return true;
	}else
	{
	  return false;
	}
}


//-----------------------------function------------------------------------------

//str format like aaa,bbb,ccc
function strToSele(str, flag, sele)
{
	sele.options.length = 0;
	var strArr = str.split(flag);
	for(i=0; i<strArr.length; i++)
	{
		sele.options[i] = new Option(strArr[i], strArr[i]);
	}
}

//str format like 1:aaa,2:bbb,3:ccc
function strToSele2(str, flag1, flag2, sele)
{
	sele.options.length = 0;
	var strArr = str.split(flag1);
	for(i=0; i<strArr.length; i++)
	{
		tempStr = strArr[i];
		tempArr = tempStr.split(flag2);
		sele.options[i] = new Option(tempArr[1], tempArr[0]);
	}
}

function getCheckboxValue(ckBoxName)
{
	var ckBoxValue = "";
	names = document.getElementsByName(ckBoxName);
	for(var i = 0; i < names.length; i++)
	{
		if(names[i].checked == true)
		{
			ckBoxValue += names[i].value+",";
		}
	}
	if(ckBoxValue != "")
		ckBoxValue = ckBoxValue.substring(0, ckBoxValue.length-1);
	return ckBoxValue;
}

function seleAll(ckBoxName, myChecked)
{
	names = document.getElementsByName(ckBoxName);
	for(var i = 0; i < names.length; i++)
	{
		names[i].checked = myChecked
	}
}

function seleFan(ckBoxName)
{
	names = document.getElementsByName(ckBoxName);
	for(var i = 0; i < names.length; i++)
	{
		if(names[i].checked == true)
		{
			names[i].checked = false;
		}else
		{
			names[i].checked = true
		}
	}
}

//check form elements
function checkForm(aForm)
{
	var eles = aForm.elements;
	for(var i= 0; i < eles.length; i++)
	{
		if(eles[i].getAttribute("autoCheck")=="blank" && trim(eles[i].value)=="")
		{
			alert(eles[i].getAttribute("autoWarn"));
			eles[i].focus();
			return false;
		}else if(eles[i].getAttribute("autoCheck")=="number" && !checkNum(eles[i].value))
		{
			alert(eles[i].getAttribute("autoWarn"));
			eles[i].focus();
			return false;
		}else if(eles[i].getAttribute("autoCheck")=="decimal" && !checkNumWithDot(eles[i].value))
		{
			alert(eles[i].getAttribute("autoWarn"));
			eles[i].focus();
			return false;			
		}
	}
	return true;
}

//deal select which item is selected
function dealSeleItem(seleId, seleValue)
{
	var allOptions = document.getElementById(seleId).options;

    for(i=0; i<allOptions.length; i++)
	{
 		if(document.getElementById(seleId).options[i].value == seleValue)
 	 	{
 	    	document.getElementById(seleId).options[i].selected=true;
 	   	}
	}
}

//---------------------------------ajax--------------------------------

var httpRequest = false;
function doAjax(url, func)
{
	httpRequest = false;
	if(window.ActiveXObject)  //IE
	{
		try
		{
			httpRequest = new ActiveXObject('Msxml2.XMLHTTP');
		}catch(e)
		{
			try
			{
				httpRequest = new ActiveXObject('Microsoft.XMLHttp');
			}catch(e) {}
		}
	}else if(window.XMLHttpRequest)  //Mozilla
	{
		httpRequest = new XMLHttpRequest();
		if(httpRequest.overrideMineType)
		{
			httpRequest.overrideMineType('text/xml');
		}
	}
	
	if(!httpRequest)
	{
		alert('Can not create instance of XMLHttpRequest');
		return false;
	}
	
	httpRequest.onreadystatechange = function() 
	{
		//4:complete, 200:success return
		if(httpRequest.readyState == 4)
		{
			if(httpRequest.status == 200)
			{
				eval(func);
			}else
			{
				alert('a problem is occured when request');
			}
		}
	  
	}

	httpRequest.open('post',url,true);
	httpRequest.send(null);
}

//use prototype
function ajaxReq(url, params, func)
{
	new Ajax.Request(url, {method:"post", onComplete:eval(func), parameters:params});
	return false;
}

function ajaxUp(url, params, succ, func)
{
	new Ajax.Updater(succ, url, {asynchronous:true,evalScripts:true,onComplete:function(e){eval(func)},parameters:params});
	return false;
}

function ajaxUpSF(url, params, succ, fail, func)
{
	new Ajax.Updater({success:succ,failure:fail}, url, {asynchronous:true,evalScripts:true,onComplete:function(e){eval(func)},parameters:params});
	return false;
}

function ajaxUpForm(url, formName, succ, func)
{
	new Ajax.Updater(succ, url, {method:'post',asynchronous:true,evalScripts:true,onComplete:function(e){eval(func)},parameters:Form.serialize(formName)});
	return false;
}



